#!/usr/bin/perl
#
# Insert textfile as log entries
#
use FileTable::Log;

$table = shift;
$file = $ENV{COUNTER_ROOT} . "/db/" . $table . ".txt";

open(FILE, $file) || die "Unable to open $file\n";
while (<FILE>) {
    if (/^\/\//) {
	$newkey = $';
	chop $newkey;
	process();
	$key = $newkey;
    } else {
	$obj .= $_;
    }
}

sub process {
    my $date;

    return if !defined($key);

    if ($obj =~ /f_mtime:(.*)/) {
	$date = $1;
    } elsif ($obj =~ /recdate:(.*)/) {
	my $datestr = $1;
	my $time = HTTP::Date::str2time($datestr);
	if ($time) {
	    $date = HTTP::Date::time2iso($time);
	}
    }
    if ($obj =~ /^f_state:DELETED/) {
      FileTable::Log::writelog($table, $key, $obj, $date, "log", "delete");
    } else {
      FileTable::Log::writelog($table, $key, $obj, $date, "log", "rollin");
    }
    undef $obj;
    undef $key;
}

	



    
